package com.sam.widget.headerBar;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.sam.widget.R;


/**
 * Created by Administrator on 2016/6/8.
 */
public class LeftTextTitleBar extends BaseTitleBar{
    private String leftText;
    private int leftTextColor = Color.WHITE;
    private int leftTextSize = 28;
    private Drawable leftTextDrawable;
    private int leftTextDrawablePadding = 10;

    private TextView leftTextView;

    public LeftTextTitleBar(Context context) {
        this(context,null);
    }

    public LeftTextTitleBar(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public LeftTextTitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void getAttrs(AttributeSet attrs) {
        super.getAttrs(attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LeftTextTitleBar);
        leftText=ta.getString(R.styleable.LeftTextTitleBar_leftText);
        leftTextColor=ta.getColor(R.styleable.LeftTextTitleBar_leftTextColor,leftTextColor);
        leftTextSize=ta.getDimensionPixelSize(R.styleable.LeftTextTitleBar_leftTextSize,leftTextSize);
        leftTextDrawable=ta.getDrawable(R.styleable.LeftTextTitleBar_leftTextDrawable);
        leftTextDrawablePadding=ta.getDimensionPixelSize(R.styleable.LeftTextTitleBar_leftTextDrawablePadding,leftTextDrawablePadding);
        ta.recycle();
    }

    @Override
    protected void findView() {
        super.findView();
        leftTextView = new TextView(context);
        leftTextView.setText(leftText);
        leftTextView.setTextColor(leftTextColor);
        leftTextView.setTextSize(leftTextSize);
        if(leftTextDrawable != null){
            leftTextDrawable.setBounds(0,0,leftTextDrawable.getMinimumWidth(),leftTextDrawable.getMinimumHeight());
            leftTextView.setCompoundDrawables(leftTextDrawable,null,null,null);
            leftTextView.setCompoundDrawablePadding(leftTextDrawablePadding);
        }
    }

    @Override
    public View getLeftView() {
        return leftTextView;
    }
}
